
let list = {} as { [key: string]: Array<Function>; };
const Bus = {
  // 订阅
  $on (name: string, fn: Function) {
    list[name] = list[name] || [];
    list[name].push(fn);
  },

  // 发布
  $emit (name: string, data?: any) {
    if (list[name]) {
      list[name].forEach((fn: Function) => {
        fn(data);
      });
    }
  },

  // 取消订阅
  $off (name: string) {
    if (list[name]) {
      delete list[name];
    }
  }

};

export default Bus;